package com.yanqu.road.server.cmd.activity.dafuweng;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.dafuweng.DFWConfig;
import com.yanqu.road.pb.monopoly.MonopolyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.dafuweng.DaFuWengMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

/**
 * 获取boss信息
 */
@Cmd(code = GameProtocol.S_DA_FU_WENG_GET_BOSS_DATA, desc = "获取boss信息")
public class DaFuWengGetBossDataCmd extends AbstractCommand {

    private int bossId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        MonopolyProto.GetBossDataReqMsg reqMsg = MonopolyProto.GetBossDataReqMsg.parseFrom(packet.getBytes());
        bossId = reqMsg.getBossId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        DFWConfig dfWConfig = DaFuWengMgr.getDfwConfig();
        ActivityInfo activityInfo = dfWConfig.getActivityInfo();
        if (!ActivityMgr.activityInTime(activityInfo)) {
            ret = GameErrorCode.E_ACTIVITY_DFW_NO_IN_TIME;
            return;
        }
        // 跨服请求boss数据
        MonopolyProto.CrossGetBossDataReqMsg.Builder builder = MonopolyProto.CrossGetBossDataReqMsg.newBuilder();
        builder.setActivityId(activityInfo.getActivityId());
        builder.setBossId(bossId);
        builder.setServerId(player.getUserInfo().getOriginalServerId());
        builder.setUserId(player.getUserId());
        player.sendUnionActivityGroupPacket(Protocol.C_CROSS_DA_FU_WENG_GET_BOSS_DATA, builder, activityInfo.getActivityId());
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            MonopolyProto.GetBossDataRespMsg.Builder builder = MonopolyProto.GetBossDataRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_DA_FU_WENG_GET_BOSS_DATA, builder);
        }
    }
}
